import Common from "../../../common/common"
let common = new Common;
let app = getApp();
Page({
  data: {
    orgSeq: "",
    goodsList: [],
    pageId: "",
    pageInfo: {}
  },
  onLoad: function (options) {

  },
  onReady: function () {
    this.setData({
      pageInfo: app.globalData.item,
      orgSeq: app.globalData.orgSeq
    })
    app.globalData.item = '';
    this.getGoodList();
  },
  getGoodList() {
    common.requestAjax("/api/flashsale-service/v1/presale/getPreSaleActGoods", "POST", {
      "orgSeq": this.data.orgSeq,
      "activityId": this.data.pageInfo.uuid
    }).then(res => {
      if (res.data.code) {
        this.setData({
          goodsList: res.data.records || []
        })
      }
    })
  },
  //我要参加
  joinActivity() {
    wx.showModal({
      title: "提示",
      content: "参与活动后不可退出,是否参与?",
      success: res => {
        if (res.confirm) {
          common.requestAjax("/api/flashsale-service/v1/presale/setGoodsStock", "POST", {
            "orgSeq": this.data.orgSeq,
            "activityId": this.data.pageInfo.uuid
          }).then(res => {
              if(res.data.code){
                wx.showToast({
                  title: "参与成功!",
                })
                this.setData({
                  [`pageInfo.joinStatus`]:1
                })
              }
          })
        }
      }
    })

  }
})